<?php
	$income = $this->income;
	$username = $this->username;
?>

<div id="admin-content">
	<div id="month">
		<h3 style="padding:10px 0px 10px 10px; margin:0px; color:#428bca; margin-bottom:20px;border-bottom: 3px solid #4cae4c;">
		Doanh thu tháng qua
		</h3>
		<div>
		<?php
			// vẽ đồ thị doanh thu trong tháng
			$days = array(31);
			$incomes = array(31);
			$today = strtotime('today');
			$past = strtotime('- 31 days', $today);
			$counter = 0;
			while($past != $today){
				$days[$counter] = date('d-m',$past);
				$past = strtotime('+1 days', $past);
				$counter++;
			}
			foreach($income as $x){
				$x['ngay'] = date('d-m',strtotime($x['ngay']));
				for($i = 0; $i < 31; $i ++){
					if(!isset($incomes[$i]))
						$incomes[$i] = 0;
					if($x['ngay'] == $days[$i]){
						$incomes[$i] += (int)$x['gia']*(int)$x['soLuong'];
					}
				}
			}
		?>
		<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
		<?php
		echo '<script>';
		echo "$(function () {
	        $('#container').highcharts({
	            title: {
	                text: 'Doanh thu tháng qua',
	                x: -20 //center
	            },
	            subtitle: {
	                text: 'Đơn vị: nghìn đồng',
	                x: -20
	            },
	            xAxis: {
	                categories: [";
	    // thời gian
	    $counter = 0;
	    foreach ($days as $value) {
	    	if($counter < 31)
	    		echo "'".substr($value, 0,2)."',";
	    	else
	    		echo "'".substr($value, 0,2)."'";
	    	# code...
	    	$counter++;
	    }
	    echo "]
	            },
	            yAxis: {
	                title: {
	                    text: 'Doanh thu (kVND)'
	                },
	                plotLines: [{
	                    value: 0,
	                    width: 1,
	                    color: '#808080'
	                }]
	            },
	            tooltip: {
	                valueSuffix: '.000 VND'
	            },
	            legend: {
	                layout: 'vertical',
	                align: 'right',
	                verticalAlign: 'middle',
	                borderWidth: 0
	            },
	            series: [{
	                name: 'Thu',
	                data: [";
	    // số liệu
	    $counter = 0;
	    foreach ($incomes as $value) {
	    	if($counter < 31)
	    		echo ($value/1000).',';
	    	else
	    		echo ($value/1000);
	    	$counter++;
	    }
	    echo "]
	            }]
	        });
	    });";
		echo '</script>';
		?>
		</div>
	</div id="week">
	<div>
		<h3 style="padding:10px 0px 10px 10px; margin:0px; color:#428bca; margin-bottom:20px;border-bottom: 3px solid #4cae4c;">
		Doanh thu theo tuần
		</h3>
		<div>

		</div>
	</div>
	<div id="customer">
		<h3 style="padding:10px 0px 10px 10px; margin:0px; color:#428bca; margin-bottom:20px;border-bottom: 3px solid #4cae4c;">
		Khách hàng mua nhiều nhất
		</h3>
		<div>

		</div>
	</div>
</div>

<style type="text/css">
	#admin-content > div{
		width: 100%;
	}
	#admin-content{
		padding-top: 0px;
		padding-bottom: 10px;
		margin: 0px auto;
	}
	#admin-content > table{
		margin: 0px auto;
		border: 1px solid #a2a2a2;
		border-collapse: collapse;
	}
	#admin-content > table tr{

	}
	#admin-content > table tr td{
		padding: 5px 10px 5px 10px;
		text-align: center;
		border: 1px solid #a2a2a2;
	}
</style>